package org.xielei.base;

import org.apache.commons.lang3.time.FastDateFormat;
import org.junit.Test;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * DateTest
 *
 * @author xielei
 * @date 2020/12/22
 */
public class DateTest {

    @Test
    public void dateTest() {
        Date date = new Date();
        Calendar instance = Calendar.getInstance();
        instance.set(2020, 11, 25, 14, 22, 22);
        Date time = instance.getTime();
        System.out.println(time);
        String format = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss").format(time);
        System.out.println(format);

        Date someDate = new Date(1590949762000L);
        System.out.println(someDate);
        System.out.println(System.currentTimeMillis());
    }

    @Test
    public void date2Test() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(5, -7);
        Date d = calendar.getTime();
        System.out.println(d);
    }

    @Test
    public void localTimeTest() {
        String nwoStr = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm"));
        System.out.println(nwoStr);
    }
}
